package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.icid.store.business.delegate.MpriceDelegate;
	import com.icid.store.event.GetMpriceListEvent;
	import com.icid.store.model.MpriceModelLocator;
	import com.icid.store.vo.MpriceVO;
	import com.icid.store.vo.PdfVO;
	
	import mx.rpc.IResponder;

	public class GetMpriceListCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:MpriceDelegate;
		private var getMpriceListEvent:GetMpriceListEvent;
		private var mpriceModel:MpriceModelLocator = MpriceModelLocator.getInstance();
		public function GetMpriceListCommand()
		{
			super();
			delegate = new MpriceDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getMpriceListEvent = GetMpriceListEvent(event);
			delegate.read(getMpriceListEvent.mid);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			mpriceModel.mpriceList.removeAll();
			for(var i:int=0;i<data.result.length;i++)
			{
				var mpriceVO:MpriceVO = new MpriceVO();
				
				mpriceVO.description = data.result[i].description;
				mpriceVO.id = data.result[i].id;
				mpriceVO.time = data.result[i].time;
				mpriceVO.title = data.result[i].title;
				mpriceVO.url = data.result[i].url;
				
				mpriceModel.mpriceList.addItem(mpriceVO);
			}
			mpriceModel.mpriceList.refresh();
		}
	}
}